package com.xzy.springboot;

import com.netflix.hystrix.contrib.metrics.eventstream.HystrixMetricsStreamServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
@EnableHystrix
@EnableCircuitBreaker
public class PaymentMain8001_hystrix {

    public static void main(String[] args) {
        SpringApplication.run(PaymentMain8001_hystrix.class,args);
    }



    /*此项配置是为了服务监控而配置,与服务容错本身无关,springcloud升级后的坑
    * servletregistrationBean因为springboot默认路径不是"/hystrix.stream"
    * 只要在自己的项目里配置Servlet就可以了*/
    @Bean
    public ServletRegistrationBean getServlet(){

        /*http://localhost:8001/hystrix.stream监控地址*/
        HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
        registrationBean.setLoadOnStartup(1);
        registrationBean.addUrlMappings("/hystrix.stream");
        registrationBean.setName("HystrixMetricsStreamServlet");
        return registrationBean;
    }

    /*此微服务配置了hystrix服务熔断
    * 1开启hystrix
    * 2在需要熔断的方法上进行配置*/
}
